﻿using System;
using TMPro;
using UnityEngine;


namespace NettyDeomo.entity
{
    public class Monster:MonoBehaviour
    {
        public int id;

        
        public Vector3 moveTarget;
        public float speed = 5;
        public bool isMoving = false;

        private TextMeshPro idText;
        public int Id
        {
            get => id;
            set
            {
                id = value;
                if (idText != null)
                {
                    idText.text = id.ToString();
                }
            }
        }

        private void Start()
        {
            idText =  GetComponentInChildren<TextMeshPro>();
        }

        private void Update()
        {
            if (isMoving)
            {
                transform.position = Vector3.MoveTowards(transform.position, moveTarget, speed * Time.deltaTime);
                if (Vector3.Distance(transform.position, moveTarget) < 0.1f)
                {
                    isMoving = false;
                }
            }
        }
    }
}